home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 003a / asmwiz16.zip / ASMWIZ.DOC < prev    next >
Text File  |  1993-05-23  |  45KB  |  1,198 lines

  1.                 The Assembly Wizard's Library            page 1
  2.                          Version 1.6
  3.  
  4.     AsmWiz  Copyright (c) 1990-1993  Thomas G. Hanlin III
  5.  
  6.  
  7.  
  8. This is AsmWiz, a library of assembly language routines for
  9. assembly language programmers. It is copyrighted and may be
  10. distributed only under the following conditions:
  11.  
  12.    All AsmWiz files must be distributed together as a unit in
  13.    unmodified form. No files may be left out or added.
  14.  
  15. YOU USE THIS LIBRARY AT YOUR OWN RISK. I have tested it on my
  16. own computer, but I will not assume responsibility for any
  17. problems which AsmWiz may cause you. If you do encounter a
  18. problem, please let me know about it, and I will do my best to
  19. verify and repair it.
  20.  
  21. It is expected that if you find AsmWiz useful, you will register
  22. your copy. You may not use AsmWiz routines in programs intended
  23. for distribution unless you have registered.
  24.  
  25. Registration gets you the latest version of AsmWiz, complete
  26. with full source code. The source code is designed for the MASM
  27. 6.0 and may require modifications to work with other assemblers.
  28.  
  29. The AsmWiz library was designed for use with small assembly
  30. programs and is compatible with the creation of COM files. All
  31. CALLs are of the NEAR variety. A FAR model will be created if
  32. there is sufficient interest.
  33.  
  34. For an example of how to set up your program to access the
  35. AsmWiz library, how to LINK the routines, and so forth, see the
  36. EXAMPLE.ASM, EXAMPLE.COM, and ?CREATE.BAT files. The file
  37. PACKING.LST tells you which ?CREATE batch file to use with which
  38. assembler. There are versions for A86, MASM, OPTASM, QuickASM,
  39. and TASM.
  40.  
  41. Note that DOS-dependent services expect DOS 2.0 or higher
  42. versions unless otherwise specified.
  43.  
  44.                        Table of Contents                 page 2
  45.  
  46.  
  47.  
  48.  Overview and Legal Info ................................... 1
  49.  
  50.  Base Conversions .......................................... 3
  51.  
  52.  Exception Handling ........................................ 4
  53.  
  54.  Delays and Countdowns ..................................... 5
  55.  
  56.  File Handling ............................................. 6
  57.  
  58.  Filename Manipulation ..................................... 8
  59.  
  60.  Keyboard Services ......................................... 9
  61.  
  62.  Long Integer Math ........................................ 10
  63.  
  64.  Memory Services .......................................... 11
  65.  
  66.  Mouse Services ........................................... 12
  67.  
  68.  Sound and Music .......................................... 13
  69.  
  70.  String Services .......................................... 14
  71.  
  72.  Telecommunications ....................................... 16
  73.  
  74.  Time and Date ............................................ 17
  75.  
  76.  Video Services ........................................... 18
  77.  
  78.  Miscellaneous Services ................................... 27
  79.  
  80.  Error Codes .............................................. 28
  81.  
  82.                        Base Conversions                  page 3
  83.  
  84.  
  85.  
  86. The Base Conversion Services provide the ability to convert back
  87. and forth between a number and its ASCIIZ representation. Any
  88. base from 2-36 may be employed, so these routines encompass
  89. binary, decimal, hex and octal conversions. Services are
  90. provided for integers and long integers, both signed and
  91. unsigned.
  92.  
  93.  
  94. The following services are available:
  95.  
  96.    BC_ASC2INT    convert ASCIIZ string to unsigned integer
  97.                        BL <-- base from which to convert
  98.                     DS:SI <-- ptr to string
  99.                     -------
  100.                        AX = unsigned integer
  101.  
  102.    BC_ASC2LONG   convert ASCIIZ string to unsigned long int
  103.                        BL <-- base from which to convert
  104.                     DS:SI <-- ptr to string
  105.                     -------
  106.                     DX,AX = unsigned long integer
  107.  
  108.    BC_ASC2SINT   convert ASCIIZ string to signed integer
  109.                        BL <-- base from which to convert
  110.                     DS:SI <-- ptr to string
  111.                     -------
  112.                        AX = signed integer
  113.  
  114.    BC_ASC2SLONG  convert ASCIIZ string to signed long integer
  115.                        BL <-- base from which to convert
  116.                     DS:SI <-- ptr to string
  117.                     -------
  118.                     DX,AX = signed long integer
  119.  
  120.    BC_INT2ASC    convert unsigned integer to ASCIIZ string
  121.                        AX <-- unsigned integer
  122.                        BL <-- base to which to convert
  123.                     ES:DI <-- ptr to string buffer (17 bytes)
  124.  
  125.    BC_LONG2ASC   convert unsigned long int to ASCIIZ string
  126.                     DX,AX <-- unsigned long integer
  127.                        BL <-- base to which to convert
  128.                     ES:DI <-- ptr to string buffer (33 bytes)
  129.  
  130.    BC_SINT2ASC   convert signed integer to ASCIIZ string
  131.                        AX <-- signed integer
  132.                        BL <-- base to which to convert
  133.                     ES:DI <-- ptr to string buffer (18 bytes)
  134.  
  135.    BC_SLONG2ASC  convert signed long integer to ASCIIZ string
  136.                     DX,AX <-- signed long integer
  137.                        BL <-- base to which to convert
  138.                     ES:DI <-- ptr to string buffer (34 bytes)
  139.  
  140.                       Exception Handling                 page 4
  141.  
  142.  
  143.  
  144. The Exception Handling Services allow your program to take
  145. control over exception conditions. This covers critical errors
  146. and Control-Break / Control-C handling.
  147.  
  148. The critical error handler gives you the ability to recover from
  149. critical errors, which would otherwise cause the infamous
  150. "R>etry, I>gnore, F>ail, A>bort?" prompt.
  151.  
  152. The break handler allows your program to ignore the Control-C
  153. and Control-Break keys or to process them in an orderly manner.
  154. This is vital if you are using any of the AsmWiz services which
  155. need to be shut down before the program terminates. Up to eight
  156. procedures can be called when ^Break or ^C are used (they will
  157. be ignored if you turn off ^Break / ^C).
  158.  
  159.  
  160. The following services are available:
  161.  
  162.  
  163.    EH_INITCRIT   initialize the critical error handler
  164.  
  165.    EH_CRITERR    check for a critical error
  166.  
  167.    EH_CRITDONE   terminates the critical error handler
  168.  
  169.    EH_INITBREAK  initialize the ^C / ^Break handler
  170.  
  171.    EH_ADDBREAK   add a procedure to be called on ^C / ^Break
  172.                        DX <-- procedure offset (CS-relative)
  173.  
  174.    EH_SETBREAK   allow or ignore ^C and ^Break
  175.                        AL <-- 0 to ignore, 1 to allow
  176.  
  177.    EH_SUBBREAK   remove a procedure to be called on ^C / ^Break
  178.                        DX <-- procedure offset (CS-relative)
  179.  
  180.                      Delays and Countdowns               page 5
  181.  
  182.  
  183.  
  184. The Delay Services are for those times when you want the
  185. computer to sit around doing nothing for a while. Delays of
  186. various timing resolution are available for anything from small
  187. to large waits.
  188.  
  189. Notes on the 100th-second delay and countdown services:
  190.  
  191. Since MD_DONE must be called before the program terminates, you
  192. should use the EH_ADDBREAK service to insure that MD_DONE is
  193. called if Control-Break or Control-C are permitted to abort the
  194. program.
  195.  
  196. Timers 0-1 may be used by AsmWiz itself for various services.
  197.  
  198. See ASMWIZ.MAN for more details on the 100th-second delay
  199. services.
  200.  
  201.  
  202. The following services are available:
  203.  
  204.  
  205.    MD_DELAY      delay for a number of 100ths of seconds
  206.                        CX <-- delay (0-32767)
  207.  
  208.    MD_DONE       terminate 100th-second delay handler
  209.  
  210.    MD_GETTIMER   get a delay count
  211.                        AL <-- timer number (0-7)
  212.                     -------
  213.                        CX = delay * 2 (0-65534)
  214.  
  215.    MD_INIT       initialize 100th-second delay handler
  216.  
  217.    MD_SETTIMER   set a delay count
  218.                        AL <-- timer number (0-7)
  219.                        CX <-- delay (0-32767)
  220.  
  221.    MD_TICK       delay for a number of clock ticks (18ths of seconds)
  222.                        CX <-- delay (0-65535)
  223.  
  224.                         File Handling                    page 6
  225.  
  226.  
  227.  
  228. The File Handling Services provide a comprehensive and powerful
  229. set of routines for file handling. The usual open file,
  230. read/write, file pointer manipulation, and close file operations
  231. are supported, of course. New conveniences include automatic
  232. network support (file sharing is used if the DOS version is high
  233. enough), optional input buffering for extra speed, and special
  234. support for text files. Critical error handling is supported via
  235. the Exception Handling Services.
  236.  
  237. These services return with the carry flag set if there is an
  238. error. In that case, the AX register returns the error code.
  239. Note that, unlike most other services, the file services are
  240. allowed to change the AX register regardless of whether an error
  241. occurred.
  242.  
  243.  
  244. The following services are available:
  245.  
  246.    DF_CLOSE      close a file
  247.                        BX <-- (virtual) file handle
  248.  
  249.    DF_DONE       terminate the File Handling Services
  250.                  (closes all open files)
  251.  
  252.    DF_FLUSH      flush a file to disk (updates disk directory)
  253.                        BX <-- (virtual) file handle
  254.  
  255.    DF_GETTIME    get file time/date stamp
  256.                        BX <-- (virtual) file handle
  257.                     -------
  258.                        AX = time
  259.                        DX = date
  260.  
  261.    DF_HANDLE     get DOS file handle given virtual file handle
  262.                        BX <-- (virtual) file handle
  263.                     -------
  264.                        BX = (DOS) file handle
  265.  
  266.    DF_INIT       initialize the File Handling Services
  267.                        DX <-- 0
  268.  
  269.    DF_LOCATE     set file read/write pointer
  270.                        BX <-- (virtual) file handle
  271.                        CL <-- 0 for offset from start
  272.                               1 for offset from current posn
  273.                               2 for offset from end of file
  274.                     DX,AX <-- offset
  275.  
  276.                         File Handling                    page 7
  277.  
  278.  
  279.  
  280.    DF_OPEN       open a file for access
  281.                        AX <-- set bit 0 for read
  282.                                   bit 1 for write
  283.                                   bit 2 for create
  284.                                   bit 3 for text file
  285.                                   bits 4-15 zero
  286.                     DS:DX <-- pointer to ASCIIZ filename
  287.                        CX <-- length of input buffer (0: none)
  288.                     ES:SI <-- pointer to input buffer, if any
  289.                     -------
  290.                        BX = (virtual) file handle
  291.  
  292.    DF_READ       read from a file
  293.                        BX <-- (virtual) file handle
  294.                        CX <-- bytes to read
  295.                               (for text files, is max bytes)
  296.                     DS:DX <-- pointer to read buffer
  297.                     -------
  298.                        AX = bytes actually read
  299.                             (if NC and not text mode)
  300.  
  301.    DF_TIME       set file time/date stamp
  302.                        BX <-- (virtual) file handle
  303.                        AX <-- time
  304.                        DX <-- date
  305.  
  306.    DF_WHERE      get file read/write pointer
  307.                        BX <-- (virtual) file handle
  308.                     -------
  309.                     DX,AX = offset
  310.  
  311.    DF_WRITE      write to a file
  312.                        BX <-- (virtual) file handle
  313.                        CX <-- bytes to write
  314.                               (for text files, is ignored)
  315.                     DS:DX <-- pointer to write buffer
  316.  
  317.                     Filename Manipulation                page 8
  318.  
  319.  
  320.  
  321. The Filename Manipulation Services allow various operations on
  322. filenames which make it possible to duplicate the capabilities
  323. of the DOS command shell. This includes finding a file which
  324. matches a specified pattern, forcing a filename to match a given
  325. pattern, splitting a filespec into its component parts, and
  326. completing a (possibly partial) filespec.
  327.  
  328.  
  329. The following services are available:
  330.  
  331.    FI_COMPLETE   complete a filespec from a partial spec
  332.                     DS:SI <-- filename (may have drive,
  333.                                  dir, "." or "..", etc)
  334.                     DS:BX <-- default extension to be added
  335.                                  (without ".")
  336.                     ES:DI <-- 80-byte buffer for result
  337.                     -------
  338.                     Flags = CY if the filespec is not valid
  339.                             NC if it went ok
  340.  
  341.    FI_MATCH      see if a filename matches a specified pattern
  342.                     DS:SI <-- pattern (may contain wildcards)
  343.                     ES:DI <-- filename (may not contain drive
  344.                                  or path specs)
  345.                     -------
  346.                     Flags = ZF if the filename matches
  347.                             NZ if the filename doesn't match
  348.  
  349.    FI_PATTERN    push a filename through a pattern spec
  350.                     DS:SI <-- filename (no drive or
  351.                                  directory allowed)
  352.                     DS:BX <-- pattern
  353.                     ES:DI <-- 13-byte buffer for results
  354.                     -------
  355.                     Flags = CY for some filename/pattern errors
  356.                             NC if it went ok
  357.  
  358.    FI_SPLIT      split a path specification into drive,
  359.                  directory, filename
  360.                     DS:SI <-- path spec
  361.                     ES:DI <-- 80-byte buffer for results
  362.  
  363.                        Keyboard Services                 page 9
  364.  
  365.  
  366.  
  367. The Keyboard Services provide access to the keyboard. They let
  368. you get and set the Caps Lock and Num Lock states, or get a key
  369. in a variety of ways. Both DOS and BIOS keyboard access is
  370. provided, so support for input redirection is optional.
  371.  
  372. Microsoft and IBM seemed to find it curiously difficult to
  373. provide a simple set of keyboard functions. These routines hide
  374. most of the quirks from you. However, there are still things to
  375. keep in mind. There is no BIOS or DOS support for setting Caps
  376. Lock or Num Lock, so it is done directly. This means that the
  377. keyboard status lights for these keys may be incorrect on older
  378. machines if you set the key states from your program. DOS does
  379. not usually support "enhanced" keyboards (101-key or more), so
  380. if you need to access enhanced keys (like F11 and F12), you
  381. can't use the DOS services or support input redirection. With
  382. the BIOS services, you must choose between compatibility (old
  383. keyboard handling, ignores F11, F12, etc if present) and full
  384. enhanced mode support (doesn't work on older machines).
  385.  
  386. The prefix for the keyboard routine is based on the way keyboard
  387. access is done:
  388.  
  389.    MK_    machine-level keyboard access (direct to hardware)
  390.    BKO_   old BIOS keyboard access (compatible with everything)
  391.    BK_    new BIOS keyboard access (only for "enhanced" kbd)
  392.    DK_    DOS keyboard access (supports input redirection)
  393.  
  394.  
  395. Background info aside, these routines are really quite simple:
  396.  
  397.    BKO_GETKEY    get a key from the keyboard (bit flags: set
  398.    BK_GETKEY      bit 0 to wait for key, 1 to screen extended
  399.    DK_GETKEY      keys, 2 to capitalize, 3 to clear kbd buffer)
  400.                          AL <-- bit flags
  401.                     -------
  402.                          AX = key (- ext'ded., 0 none, + ASCII)
  403.                          Flags = NZ if got a key, ZF if no key
  404.  
  405.    BKO_GETCAPS   get state of Caps Lock (compatible)
  406.    BK_GETCAPS    get state of Caps Lock (enhanced kbd only)
  407.                     -------
  408.                          AX = 0 if off, 0FFFFh if on
  409.  
  410.    BKO_GETNUM    get state of Num Lock (compatible)
  411.    BK_GETNUM     get state of Num Lock (enhanced kbd only)
  412.                     -------
  413.                          AX = 0 if off, 0FFFFh if on
  414.  
  415.    MK_SETCAPS    set state of Caps Lock
  416.                          AX <-- 0 to turn off, non-0 to turn on
  417.  
  418.    MK_SETNUM     set state of Num Lock
  419.                          AX <-- 0 to turn off, non-0 to turn on
  420.  
  421.                        Long Integer Math                page 10
  422.  
  423.  
  424.  
  425. The Long Integer Math Services provide support for the basic
  426. arithmetic operations on unsigned long integers. They allow you
  427. to add two 32-bit integers, subtract one 32-bit integer from
  428. another, multiply two 32-bit integers (giving a 64-bit result),
  429. and divide a 63-bit integer by a 32-bit integer (giving a 32-bit
  430. result and 32-bit remainder).
  431.  
  432. Since 32-bit integers are rather unwieldy unless you're using an
  433. 80386 or above (in which case you don't need these services
  434. anyway), the numbers are passed back and forth through a buffer
  435. in memory.
  436.  
  437.  
  438. The following services are available:
  439.  
  440.    MA_ADD32      add two unsigned long integers
  441.                     DS:SI   <-- first operand
  442.                     DS:SI+4 <-- second operand
  443.                     -------
  444.                     DS:SI+8 = result
  445.  
  446.    MA_DIV32      divide an unsigned 63-bit integer by an
  447.                  unsigned long integer
  448.                     DS:SI   <-- dividend (64 bits: high bit=0)
  449.                     DS:SI+8 <-- divisor (unsigned long int)
  450.                     -------
  451.                     DS:SI+12 = quotient (unsigned long int)
  452.                     DS:SI+16 = remainder (unsigned long int)
  453.  
  454.    MA_MUL32      multiply two unsigned long integers
  455.                     DS:SI   <-- first operand
  456.                     DS:SI+4 <-- second operand
  457.                     -------
  458.                     DS:SI+8 = result (unsigned very long
  459.                                  integer: 64 bits)
  460.  
  461.    MA_SUB32      subtract one unsigned long int from another
  462.                     DS:SI   <-- first operand
  463.                     DS:SI+4 <-- second operand
  464.                     -------
  465.                     DS:SI+8 = result
  466.  
  467.                         Memory Services                 page 11
  468.  
  469.  
  470.  
  471. The Memory Services provide low-level routines for memory
  472. manipulation. They allow you to manipulate addresses, provide a
  473. "smart" block move service that automatically handles overlaps
  474. between source and destination areas, and allows you to save or
  475. restore blocks of memory in BASIC's BSAVE format.
  476.  
  477. Among the address manipulation services are routines to convert
  478. an address to have the smallest possible segment and highest
  479. possible offset (or vice versa) to allow REP operations to
  480. always handle up to 65,519 bytes without wrapping within the
  481. segment. This can also be useful in file operations.
  482.  
  483.  
  484. The following services are available:
  485.  
  486.    ME_BINFO      get information about a BSAVE-format file
  487.                     DS:DX <-- pointer to ASCIIZ filename
  488.                     -------
  489.                     ES:SI = segment:offset
  490.                        CX = image size (bytes)
  491.                     Flags = CY if unable to load file
  492.                             if CY, AX is error code
  493.  
  494.    ME_BLOAD      load a BSAVE-format file into memory
  495.                     DS:DX <-- pointer to ASCIIZ filename
  496.                     -------
  497.                     Flags = CY if unable to load file
  498.                             if CY, AX is error code
  499.  
  500.    ME_BSAVE      save a block of memory to a BSAVE-format file
  501.                     DS:DX <-- pointer to ASCIIZ filename
  502.                     ES:SI = segment:offset
  503.                        CX = image size (bytes)
  504.                     -------
  505.                     Flags = CY if unable to save memory
  506.                             if CY, AX is error code
  507.  
  508.    ME_HIGHOFS    convert an address to have the lowest segment
  509.                  & highest offset
  510.                     DX:AX <-- segment:offset
  511.                     -------
  512.                     DX:AX = converted segment:offset
  513.  
  514.    ME_LOWOFS     convert an address to have the highest segment
  515.                  & lowest offset
  516.                     DX:AX <-- segment:offset
  517.                     -------
  518.                     DX:AX = converted segment:offset
  519.  
  520.    ME_MOVE       move a block of memory w/o overlap conflicts
  521.                     DS:SI <-- source segment:offset
  522.                     ES:DI <-- destination segment:offset
  523.                        CX <-- bytes to move (0 - 65,519)
  524.  
  525.                         Mouse Services                  page 12
  526.  
  527.  
  528.  
  529. The Mouse Services provide a simple set of functions for dealing
  530. with Microsoft-compatible mouse devices. You may see if a mouse
  531. exists, control the mouse cursor, and get information about the
  532. mouse buttons.
  533.  
  534.  
  535. The following services are available:
  536.  
  537.    MO_GLOCATE    set the mouse cursor location (graphics)
  538.                        CX = X coordinate (0-MaxX)
  539.                        DX = Y coordinate (0-MaxY)
  540.  
  541.    MO_GWHERE     get the mouse cursor location & button states
  542.                        AL = left button (1: pressed, 0: not)
  543.                        AH = right button (1: pressed, 0: not)
  544.                        CX = X coordinate (0-MaxX)
  545.                        DX = Y coordinate (0-MaxY)
  546.  
  547.    MO_HIDECURSOR hide the mouse cursor
  548.  
  549.    MO_INIT       see if a mouse is installed
  550.                     -------
  551.                        AL = number of mouse buttons
  552.                             (0 if no mouse)
  553.  
  554.    MO_LOCATE     set the mouse cursor location (text)
  555.                        DH <-- row (1-25)
  556.                        DL <-- column (1-80)
  557.  
  558.    MO_RANGE      set the mouse cursor range (text)
  559.                        CH <-- top row (1-25)
  560.                        CL <-- leftmost column (1-80)
  561.                        DH <-- bottom row (1-25)
  562.                        DL <-- rightmost column (1-80)
  563.  
  564.    MO_SHOWCURSOR show the mouse cursor
  565.  
  566.    MO_WHERE      get the mouse cursor location & button states
  567.                     -------
  568.                        AL = left button (1: pressed, 0: not)
  569.                        AH = right button (1: pressed, 0: not)
  570.                        DH = row (1-25)
  571.                        DL = column (1-80)
  572.  
  573.                         Sound and Music                 page 13
  574.  
  575.  
  576.  
  577. The Sound and Music Services provide the ability to generate
  578. sound effects and music. The current service is rather on the
  579. primitive side. It will be supplemented by a background
  580. (interrupt-driven) music command language in a future version of
  581. AsmWiz.
  582.  
  583.  
  584. The following services are available:
  585.  
  586.    MU_SOUND      produce a sound of a specified duration
  587.                  and frequency
  588.                     AX <-- frequency (Hertz or cycles/second:
  589.                               about 50-4000 is useful)
  590.                     DX <-- duration  (18ths of seconds)
  591.  
  592.                    String Services (ASCIIZ)             page 14
  593.  
  594.  
  595.  
  596. The ASCIIZ String Services provide an assortment of services for
  597. dealing with NUL-terminated strings.
  598.  
  599. Note that, although many of the string services are designed to
  600. place the result of processing a first string into a second
  601. string, it is not actually necessary to use two string buffers.
  602. The services are designed so that you can place the results back
  603. into the original string buffer by using the same address for
  604. both strings.
  605.  
  606.  
  607. The following routines are included amongst the ASCIIZ String
  608. Services:
  609.  
  610.    S0_COMPARE    compare two strings
  611.                     DS:SI <-- first string
  612.                     ES:DI <-- second string
  613.                     -------
  614.                     Flags = ZF if equal, NZ if not equal
  615.                             CY if first < second
  616.                             NC if first >= second
  617.  
  618.    S0_DUPE       form a string by duplicating a character
  619.                     ES:DI <-- result string
  620.                        AL <-- character to duplicate
  621.                        CX <-- number of times to repeat
  622.  
  623.    S0_FIND       search for a substring within a string
  624.                     DS:SI <-- substring
  625.                     ES:DI <-- string
  626.                     -------
  627.                        AX = position of substring in string
  628.                          (0 if not found; ZF set accordingly)
  629.  
  630.    S0_LEFT       copy a specified section from the left of
  631.                  a string
  632.                     DS:SI <-- source string
  633.                        CX <-- number of characters to copy
  634.                     ES:DI <-- result string
  635.  
  636.    S0_LENGTH     get the length of a string (excluding the
  637.                  null terminator)
  638.                     DS:SI <-- string
  639.                     -------
  640.                        CX = string length
  641.  
  642.    S0_LOCASE     convert a string to lowercase (international)
  643.                     DS:SI <-- source string
  644.                     ES:DI <-- result string
  645.  
  646.    S0_LOCASES    convert a string to lowercase (American)
  647.                     DS:SI <-- source string
  648.                     ES:DI <-- result string
  649.  
  650.                    String Services (ASCIIZ)             page 15
  651.  
  652.  
  653.  
  654.    S0_MID        copy a specified section of a string
  655.                     DS:SI <-- source string
  656.                        DX <-- where to start copying from (1-xx)
  657.                        CX <-- how many characters to copy
  658.                     ES:DI <-- result string
  659.  
  660.    S0_RIGHT      copy a specified section from the right side
  661.                  of a string
  662.                     DS:SI <-- source string
  663.                        CX <-- number of characters to copy
  664.                     ES:DI <-- result string
  665.  
  666.    S0_TRIM       trim the "white space" (blanks and control
  667.                  codes) from either or both sides of a string
  668.                     DS:SI <-- source string
  669.                        AL <-- set bit 0 to trim the left
  670.                                   bit 1 to trim the right
  671.                     ES:DI <-- result string
  672.  
  673.    S0_UPCASE     convert a string to uppercase (international)
  674.                     DS:SI <-- source string
  675.                     ES:DI <-- result string
  676.  
  677.    S0_UPCASES    convert a string to uppercase (American)
  678.                     DS:SI <-- source string
  679.                     ES:DI <-- result string
  680.  
  681.                       Telecommunications                page 16
  682.  
  683.  
  684.  
  685. The Telecommunications Services provide functions that are
  686. useful for telecommunications. At the moment, this is limited to
  687. services that aid in performing file transfers and similar
  688. functions.
  689.  
  690.  
  691. The following routines are included amongst the
  692. Telecommunications Services:
  693.  
  694.    TC_CHKSUM     calculate the checksum for a block of data
  695.                     DS:SI <-- pointer to a data block
  696.                        CX <-- length of data block (in bytes)
  697.                     -------
  698.                        AX = checksum
  699.  
  700.    TC_CRC        calculate the 16-bit CRC of a block of data
  701.                     DS:SI <-- pointer to a data block
  702.                        CX <-- length of data block (in bytes)
  703.                     -------
  704.                        AX = resulting CRC
  705.  
  706.                     Time and Date Services              page 17
  707.  
  708.  
  709.  
  710. The Time and Date Services provide international time and date
  711. handling. Based on the country code given it by DOS, these
  712. services return strings that represent the current time or date
  713. in the appropriate format for that country.
  714.  
  715. These services provide a simple way to make your software work
  716. properly on any computer anywhere, across the world.
  717.  
  718. See the COUNTRY entry under CONFIG.SYS in your DOS manual for
  719. more details. Note that DOS version 3.0 or greater is required
  720. to ensure that the date and time delimiters are appropriate.
  721. Otherwise, the date and time formats will still be correct, but
  722. the delimiters used will be assumed to be "-" for the date and
  723. ":" for the time. With DOS versions before 3.0, the time will be
  724. presented in 12-hour (am/pm) format.
  725.  
  726.  
  727. The following routines are included amongst the Time and Date
  728. Services:
  729.  
  730.    TD_GETDATE    get the current date as an ASCIIZ string
  731.                  DS:DX <-- pointer to a buffer (11 bytes)
  732.                     AL <-- 0 for 2-digit year
  733.                            1 for 4-digit year
  734.  
  735.    TD_GETTIME    get the current time as an ASCIIZ string
  736.                  DS:DX <-- pointer to a buffer (8 bytes)
  737.  
  738.                         Video Services                  page 18
  739.  
  740.  
  741.  
  742. Displaying text is something that almost every program will do.
  743. The AsmWiz library contains numerous sets of video services
  744. which make it easy to use the display in a consistent manner.
  745.  
  746. The display services are divided into five sets of routines,
  747. each of which provides similar capabilities:
  748.  
  749.    DV    DOS-level services
  750.    BV    BIOS-level services
  751.    MV    Machine-level services for text modes
  752.    CG    Machine-level services for CGA graphics modes
  753.    HG    Machine-level services for Hercules graphics mode
  754.  
  755. The DOS services provide the maximum level of compatibility.
  756. They are also the slowest of the video services and the least
  757. flexible. The main practical advantage of using DOS services is
  758. that they allow redirection, so the output of your program can
  759. be sent to a file, a printer, or a serial port as well as to the
  760. display. Since DOS itself has only minimal video support, you
  761. will need to make sure an ANSI driver is installed before using
  762. these services. See your DOS manual on ANSI.SYS for more
  763. information if you need it.
  764.  
  765. The BIOS services provide a very good level of compatibility.
  766. They are faster and more flexible than the DOS services. Like
  767. the DOS services, these routines are quite likely to work on
  768. nonstandard displays.
  769.  
  770. The machine-level services are the least compatible. They will
  771. work on any standard PC clone, but not on semi-compatible
  772. hardware or with nonstandard display devices. In return for this
  773. disadvantage, these services are much faster than the other
  774. services and provide a great deal more flexibility. Only the
  775. machine-level services support Hercules graphics mode.
  776.  
  777.                         Video Services                  page 19
  778.                      Text Display Speeds
  779.  
  780.  
  781.  
  782. Speed tests were conducted on an 8088 machine with a Phoenix
  783. BIOS, running MS-DOS 3.30. "Your mileage may differ". The tests
  784. were conducted on how quickly strings could be printed to the
  785. display.
  786.  
  787. Speeds are listed relative to the slowest display method (DOS
  788. services).
  789.  
  790.  
  791.  
  792.              +-----------+-----------+-----------+-----------+
  793.              | DV_STROUT | BV_STROUT | MV_STROUT | CG_STROUT |
  794. +------------+-----------+-----------+-----------+-----------+
  795. | Mode 3     |           |           |           |           |
  796. | text mode  |    100%   |    162%   |    572%   |    n/a    |
  797. +------------+-----------+-----------+-----------+-----------+
  798. | Mode 4     |           |           |           |           |
  799. | CGA lo-res |    100%   |    114%   |    n/a    |    180%   |
  800. +------------+-----------+-----------+-----------+-----------+
  801. | Mode 6     |           |           |           |           |
  802. | CGA hi-res |    100%   |    122%   |    n/a    |    204%   |
  803. +------------+-----------+-----------+-----------+-----------+
  804.  
  805.  
  806.  
  807. From this chart, you can see that using BIOS display services is
  808. 14% - 62% faster than using DOS services. Using machine-level
  809. services is 80% - 472% faster than using DOS services, and about
  810. 60% - 250% faster than using BIOS services.
  811.  
  812. If system compatibility is a major concern, then note that the
  813. DOS services are most compatible, followed by the BIOS services
  814. and then the machine-level services. The price you pay for
  815. compatibility is speed and flexibility. The machine-level
  816. services are the fastest and most flexible, followed by the BIOS
  817. services and then the DOS services.
  818.  
  819. It must be noted that almost all machines these days are 100%
  820. compatible and will run any of these routines with no problem.
  821.  
  822.                         Video Services                  page 20
  823.                    General Video Information
  824.           (not applicable to Hercules graphics mode)
  825.  
  826.  
  827.  
  828. For all text routines, color/attributes are encoded as a single
  829. byte value:
  830.  
  831. bit:    7   6   5   4   3   2   1   0
  832.       +---+---+---+---+---+---+---+---+
  833.       | B |  backgnd  | I |  foregnd  |
  834.       +---+---+---+---+---+---+---+---+
  835.  
  836. B:  "blink".  Set if the color is blinking.
  837.  
  838. I:  "intense".  Set if the foreground color is intense
  839.     (bright or light).
  840.  
  841. backgnd, foregnd:  the actual foreground and background
  842.    colors.  The bits specify the red, green, and blue
  843.    components of the color, giving the following color list:
  844.  
  845.        0    black     (if intense, usually displayed as gray)
  846.        1    blue
  847.        2    green
  848.        3    cyan
  849.        4    red
  850.        5    magenta
  851.        6    brown     (if intense, usually displayed as yellow)
  852.        7    white
  853.  
  854.  
  855. Text in CGA graphics modes is different. If you use BIOS or DOS
  856. services, you may only specify a foreground color, which may be
  857. 0-3. If you use the CGA machine-level services, you may specify
  858. a background color as well as a foreground color. Color encoding
  859. is the same as for text mode, with the exception that there are
  860. no "blinking" or "intense" bits, and the color range is 0-3
  861. instead of 0-7. The 0-3 range does not follow the above color
  862. list; instead, the colors depend on which CGA palette is in use.
  863.  
  864.                         Video Services                  page 21
  865.                    General Video Information
  866.  
  867.  
  868.  
  869. Screen modes are specified as a single byte, as follows:
  870.  
  871.      Mode  Resolu.  Type  Colr  Use      Adapter   Services
  872.  
  873.        0   40x25    b&w     16  text       CGA     MV, BV, DV
  874.        1   40x25    color   16  text       CGA     MV, BV, DV
  875.        2   80x25    b&w     16  text       CGA     MV, BV, DV
  876.  def-  3   80x25    color   16  text       CGA     MV, BV, DV
  877.        4   320x200  color    4  graphics   CGA     CG, BV, DV
  878.        5   320x200  b&w      4  graphics   CGA     CG, BV, DV
  879.        6   640x200  color    2  graphics   CGA     CG, BV, DV
  880.  mda-  7   80x25    b&w      -  text       MDA     BV
  881.       13   320x200  color   16  graphics   EGA     BV
  882.       14   640x200  color   16  graphics   EGA     BV
  883.       15   640x350  mono     -  graphics   EGA     BV
  884.       16   640x350  color   16  graphics   EGA     BV
  885.       17   640x480  color    2  graphics   VGA     BV
  886.       18   640x480  color   16  graphics   VGA     BV
  887.       19   320x200  color  256  graphics   VGA     BV
  888.  
  889. BV = BIOS video services
  890. DV = DOS video services
  891. MV = Machine-level text services
  892. CG = Machine-level CGA graphics services
  893.  
  894.                         Video Services                  page 22
  895.  
  896.  
  897.  
  898. All of the video services share a common nomenclature and
  899. calling procedure. For many of the services, you will have a
  900. choice of whether to use DOS, BIOS, Machine-level (text modes),
  901. Machine-level (CGA graphics modes), or Machine-level (Hercules
  902. graphics mode). The level is specified as a two-letter code
  903. prefix to the routine name, where the codes are as follows:
  904.  
  905.     DV    DOS Video
  906.     BV    BIOS Video
  907.     MV    Machine-level (text mode) Video
  908.     CG    Machine-level (CGA graphics mode) Video
  909.     HG    Machine-level (Hercules graphics mode) Video
  910.  
  911. For instance, the routine to display a string using DOS is
  912. called DV_STROUT (DOS Video service, String Output). Note that
  913. it usually isn't a good idea to "mix and match" video services
  914. of different types at the same time.
  915.  
  916.  
  917. The following services are available:
  918.  
  919.  
  920.     CHROUT      display a character
  921.                 BV,DV,MV,CG,HG
  922.                    AL <-- character
  923.  
  924.     CLS         clear the screen and home the cursor
  925.                 BV,DV,MV,CG,HG
  926.  
  927.     COLOR       set the text color
  928.                 BV,DV,MV,CG,HG
  929.                    AL <-- color/attribute
  930.  
  931.     CRLF        display a carriage return and a linefeed
  932.                 BV,DV,MV,CG,HG
  933.  
  934.     CLEOLN      clear from the cursor to the end of the line
  935.                 BV,DV,MV,CG,HG
  936.  
  937.     DELCHR      delete the character at the cursor
  938.                 MV
  939.  
  940.     DELLINE     delete the current line
  941.                 BV,dv,MV
  942.  
  943.     GETCOLOR    get the text color
  944.                 BV,MV,CG,HG
  945.                    -------
  946.                    AL = color/attribute
  947.  
  948.                         Video Services                  page 23
  949.  
  950.  
  951.  
  952.     GETMODE     get the current screen mode
  953.                 BV,MV
  954.                    -------
  955.                    AL = mode
  956.  
  957.     FIXCOLOR    whether to convert colors to monochrome
  958.                 BV,DV,MV
  959.                    AL <-- whether to convert (0 no, 1 yes)
  960.  
  961.     FRAME       display a window frame
  962.                 MV
  963.                    CH,CL <-- upper left corner (row, column)
  964.                    DH,DL <-- lower right corner (row, column)
  965.                    DS:SI <-- frame char list (-1 to -9 special)
  966.  
  967.     HIDECURSOR  hide the cursor
  968.                 BV,MV
  969.  
  970.     INIT        initialize the video service routines
  971.                 MV,CG
  972.  
  973.     INSCHR      insert a space at the cursor
  974.                 MV
  975.  
  976.     INSLINE     insert a row at the current line
  977.                 BV,dv,MV
  978.  
  979.     LOCATE      set the cursor position
  980.                 BV,DV,MV,CG,HG
  981.                    DH <-- row (1-25/43)
  982.                    DL <-- column (1-40/80/90)
  983.  
  984.     MODE        set the screen mode
  985.                 BV,DV,MV,CG,HG
  986.                    AL <-- mode (see General Video Info)
  987.  
  988.     POPUP       display a pop-up window
  989.                 BV,MV
  990.                    DS:DX <-- parameter pointer
  991.  
  992.     SAVESIZE    calculate bytes needed to save a screen area
  993.                 MV
  994.                    -------
  995.                    AL = bytes
  996.  
  997.                         Video Services                  page 24
  998.  
  999.  
  1000.  
  1001.     SCRREST     restore a saved screen area from a buffer
  1002.                 MV
  1003.                    DS:SI <-- buffer pointer
  1004.                    DH,DL <-- upper left corner (row, column)
  1005.  
  1006.     SCRSAVE     save a screen area into a buffer
  1007.                 MV
  1008.                    ES:DI <-- buffer pointer
  1009.                    CH,CL <-- upper left corner (row, column)
  1010.                    DH,DL <-- lower right corner (row, column)
  1011.                    -------
  1012.                       AX = bytes used to save screen area
  1013.  
  1014.     SHOWCURSOR  show the cursor
  1015.                 BV,MV
  1016.  
  1017.     STROUT      display a string
  1018.                 BV,DV,MV,CG,HG
  1019.                    DS:DX <-- pointer to ASCIIZ string
  1020.  
  1021.     WHERE       get the current cursor position
  1022.                 BV,MV,CG,HG
  1023.                    DH <-- row (1-25/43)
  1024.                    DL <-- column (1-40/80/90)
  1025.  
  1026.                         Video Services                  page 25
  1027.  
  1028.  
  1029.  
  1030. The ability to display graphics was once limited and very
  1031. expensive, but this is no longer true. PC-class computers have a
  1032. wide variety of graphics standards to choose from. This is
  1033. useful whether you are interested in games, business charts,
  1034. computer-aided design, icon-based mouse interfaces, or any
  1035. number of other applications. The AsmWiz library provides
  1036. numerous sets of graphics services which allow easy access to
  1037. the capabilities of whatever display is installed.
  1038.  
  1039. The graphics services are divided into sets of routines, with
  1040. each set of routines handling a specific video mode or modes.
  1041. This makes it possible to support just the modes you want,
  1042. without extraneous code being linked in.
  1043.  
  1044. All graphics services are machine-level and demand hardware
  1045. compatibility of both your computer and video adapter. This is
  1046. necessary because DOS doesn't support graphics at all, and the
  1047. BIOS only supports very slow single-pixel handling. If you are
  1048. able to run standard graphics programs on your computer,
  1049. however, you should experience no problems with these services.
  1050.  
  1051. All of the graphics services share a common nomenclature and
  1052. calling procedure. The video mode is specified as a two-letter
  1053. code prefix to the routine name, where the codes are as follows:
  1054.  
  1055.    Prefix     Mode(s)     Adapter     Resolution(s)     Colors
  1056.    ------    --------     -------    ----------------   ------
  1057.      G13        13h         VGA           320x200         256
  1058.      G4        4, 5         CGA           320x200           4
  1059.      G6          6          CGA           640x200           2
  1060.      GD         0Dh         EGA           320x200          16
  1061.      GE         0Eh         EGA           640x200          16
  1062.      GE         10h         EGA           640x350          16
  1063.      GE         11h         VGA           640x480           2
  1064.      GE         12h         VGA           640x480          16
  1065.      GH      Hercules       HGA           720x348           2
  1066.  
  1067. The service to display a line in Mode 6, for example, is named
  1068. G6_LINE.  Note that GE_ covers most EGA and VGA modes.
  1069.  
  1070.                         Video Services                  page 26
  1071.  
  1072.  
  1073.  
  1074. The following graphics services are available:
  1075.  
  1076.  
  1077.     BOX         draw a box
  1078.                 GH,G4,G6,GD,GE,G13
  1079.                    CX <-- left X coordinate
  1080.                    DX <-- top Y coordinate
  1081.                    SI <-- right X coordinate
  1082.                    DI <-- bottom Y coordinate
  1083.                    AH <-- whether to fill box (0 no, 1 yes)
  1084.                    AL <-- color
  1085.  
  1086.     GETPEL      get the current color of a point
  1087.                 GH,G4,G6,G13
  1088.                    CX <-- X coordinate
  1089.                    DX <-- Y coordinate
  1090.                    -------
  1091.                    AL = color
  1092.  
  1093.     LINE        draw a line
  1094.                 GH,G4,G6,GD,GE,G13
  1095.                    CX <-- left X coordinate
  1096.                    DX <-- top Y coordinate
  1097.                    SI <-- right X coordinate
  1098.                    DI <-- bottom Y coordinate
  1099.                    AL <-- color
  1100.  
  1101.     PLOT        plot a point
  1102.                 GH,G4,G6,GD,GE,G13
  1103.                    CX <-- X coordinate
  1104.                    DX <-- Y coordinate
  1105.                    AL <-- color
  1106.  
  1107.                     Miscellaneous Services              page 27
  1108.  
  1109.  
  1110.  
  1111. The Miscellaneous Services provide a number of services for
  1112. various purposes, such as parsing the command line, determining
  1113. the active video adapter, scanning the environment for a
  1114. parameter, and generating pseudo-random numbers. They eliminate
  1115. much of the tedium of these common chores.
  1116.  
  1117.  
  1118. The following services are available:
  1119.  
  1120.    MI_BOOT       reboot the computer (warm boot)
  1121.  
  1122.    MI_GETSCREEN  see what type of display is active
  1123.                     -------
  1124.                        AH = adapter type (1-6:
  1125.                                MDA, Herc, CGA, EGA, MCGA, VGA)
  1126.                        AL = color flag (0 color, 1 mono)
  1127.  
  1128.    MI_PARSE      parse a command line into filespecs & options
  1129.                     DS:SI <-- ptr to command line
  1130.                                  (for COM files, = CS:0080h)
  1131.                     ES:DI <-- ptr to filename buffer (128b)
  1132.                     ES:BX <-- ptr to option buffer (128 bytes)
  1133.                        AL <-- switch character (normally "/")
  1134.                     -------
  1135.                        AH = number of options
  1136.                        AL = number of filenames
  1137.  
  1138.    MI_RANDOM     generate a pseudo-random number
  1139.                        DX <-- random number range (1-4000)
  1140.                     -------
  1141.                        AX = random number (0 to DX - 1)
  1142.  
  1143.    MI_RANDOMIZE  initialize the pseudo-random number generator
  1144.                        AX <-- random number seed
  1145.                                  (use 0FFFFh for auto-seeding)
  1146.  
  1147.    MI_SCANENV    scan the DOS environment for a parameter
  1148.                     DS:SI <-- ptr to the DOS environment
  1149.                                  or similar table
  1150.                     ES:DI <-- ptr to the parm to search for
  1151.                     -------
  1152.                        CY if not found
  1153.                        NC if match found
  1154.                           if NC, DS:SI points to parm value
  1155.  
  1156.                          Error Codes                    page 28
  1157.  
  1158.  
  1159.  
  1160. DOS error codes are returned by various of the DOS services,
  1161. particularly the file and disk services. The code is returned in
  1162. the AL register. This is a list of some of the possible errors.
  1163.  
  1164.  
  1165.       2      file not found
  1166.       3      path not found
  1167.       4      too many open files (no handle available)
  1168.       5      access denied
  1169.       6      invalid handle
  1170.       8      insufficient memory
  1171.      15      invalid drive specified
  1172.      16      tried to remove current directory
  1173.      18      no more files
  1174.  
  1175.  
  1176.  
  1177.  
  1178. Critical error codes are returned by the EH_CRITERR service in
  1179. the AH register. This is a list of the possible errors.
  1180.  
  1181.  
  1182.       0      no critical error (if CY, it was a DOS error)
  1183.       1      write-protected disk
  1184.       2      unknown unit
  1185.       3      drive not ready
  1186.       4      unknown command
  1187.       5      data/CRC error
  1188.       6      bad request structure length
  1189.       7      seek error
  1190.       8      unknown media type
  1191.       9      sector not found
  1192.      10      printer out of paper
  1193.      11      write fault
  1194.      12      read fault
  1195.      13      general failure
  1196.      16      invalid disk change (only used by DOS 3+)
  1197.  
  1198.